// Jordan Lloyd - 2D Destiny

// ------------------------------------------
// LEVELS:
// 01 - moon
// 02 - venus
// 03 - mars
// ------------------------------------------

// includes
#include <SGE.h> 
using namespace SGE; 

#include "FrontendState.h"
#include "PlayState.h"
#include "GameOverState.h"
#include "WinState.h"

// game context
GameContext gameContext;
// current thing were updating
GameState* currentState = nullptr;
// next 
NextState nextState = Frontend;

void SGE_Initialize()
{
}

void SGE_Terminate()
{
}

bool SGE_Update(float deltaTime)
{
	if (nextState != None)
	{
		// unload current state
		if (currentState != nullptr)
		{
			currentState->Unload();
			delete currentState;
		}

		// change state
		switch (nextState)
		{
		case Frontend:
			currentState = new FrontendState(gameContext);
			break;
		case Gameplay:
			currentState = new PlayState(gameContext);
			break;
		case GameOver:
			currentState = new GameOverState(gameContext);
		case Win:
			currentState = new WinState(gameContext);
			break;
		}

		// load new state
		currentState->Load();
	}

	nextState = currentState->Update(deltaTime);

	if (nextState == Quit)
	{
		currentState->Unload();
		delete currentState;
		return true;
	}

	return false; 
}

void SGE_Render()
{
	currentState->Render();
}